//
//  ImportResultController.swift
//  XingCeHelper
//
//  Created by 申铭 on 2023/2/8.
//

import UIKit

class ImportResultController: BaseTableViewController {
    
    var results: Array<ImportResult>?

    override func viewDidLoad() {
        super.viewDidLoad()

        results = Global.shared.importResults
        
        tableView.rowHeight = UITableView.automaticDimension
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "reuseIdentifier")
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return results?.count ?? 0
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
        
        if let model = results?[indexPath.row] {
            cell.textLabel?.text = model.content
            cell.textLabel?.numberOfLines = 0
            if model.type == .failure {
                cell.textLabel?.textColor = .systemRed
            } else if model.type == .success {
                cell.textLabel?.textColor = .systemGreen
            } else {
                cell.textLabel?.textColor = .systemGray
            }
        }
        return cell
    }
}
